class @EditProfileView extends CustomView

    initialize: ->
        super
        @setElement("#main")
        @model.bind("change", @render)
        @model.fetch()
    
    render: ->
        @GetTemplate(SiteMap.Account.EditTemplate, (compiledTemplate)=>
                $(@el).html(compiledTemplate(@model.toJSON()))
                $("#Avatar").ImageUpload()
            )

    events:
        "click button.Edit":"Save"

    Save: ->
        Loading.Start()
        Messages.WriteMessage('Saving user.')
        
        data = $(@el).find("form.general").serialize()
        
        $.ajax(
            type: "POST"
            url: SiteMap.Account.Save
            data: data
            success: (response) =>
                if response.SuccessMessage? && response.SuccessMessage.length
                    Messages.WriteSuccessMessage(response.SuccessMessage);
                    Backbone.history.navigate('', trigger:true)
                    Loading.Stop()
                else
                    Messages.WriteErrors(response.Errors)
                    Loading.Stop()
        )